/**
 * 学科选择组件
 */

import React from 'react';
import Group from './Group.jsx';
import CheckButton from '../../dump/CheckButton.jsx';

import filterStyle from './Filter.less';

export default class SubjectGroup extends React.Component {
	static propTypes = {
		subjects: React.PropTypes.array,
	};

	static defaultProps = {
		subjects: [],
		checkedItems: [],
		onItemCheck: function() { }
	};

	constructor(props) {
		super(props);

		this.handleCheck = this.handleCheck.bind(this);
	}

	// 处理选择状态变化
	handleCheck(event, isChecked) {
		let { onItemCheck } = this.props;
		onItemCheck('subject', event.target.value, isChecked);
	};

	render() {
		let { subjects, checkedItems } = this.props;

		return (
			<Group name='学科'>
				<div className={filterStyle.inline}>
					<CheckButton
						key={-1}
						value={'-1'}
						checked={checkedItems.includes('-1')}
						onCheck={this.handleCheck}
						label='不限' />
					{
						subjects.map((item, index) => 
							<CheckButton
								key={index}
								value={item.enum}
								checked={checkedItems.includes(item.enum)}
								onCheck={this.handleCheck}
								label={item.name}  />)
					}
				</div>
			</Group>
		);
	}
}